<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="代征主体" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dzzt">
              <a-input v-model="model.dzzt" placeholder="请输入代征主体"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="企业名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="qymc">
              <a-input v-model="model.qymc" placeholder="请输入企业名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="代理名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dlmc">
              <a-input v-model="model.dlmc" placeholder="请输入代理名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="用户姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
              <a-input v-model="model.name" placeholder="请输入用户姓名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="身份证号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sfzh">
              <a-input v-model="model.sfzh"   placeholder="请输入身份证号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="结算金额（元）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jsje">
              <a-input v-model="model.jsje"   placeholder="请输入结算金额"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="所属服务厅" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ssfwt">
              <j-dict-select-tag type="list" v-model="model.ssfwt" dictCode="bu_gsfwpt_rlzy_jkcxpz,fwt,id" placeholder="请选择所属服务厅" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="税款所属期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="skssq">
              <j-date placeholder="请选择税款所属期" v-model="model.skssq" date-format='yyyy-MM'  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="业务类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="wslx">
              <j-dict-select-tag type="list" v-model="model.wslx" dictCode="bu_jygl_wslx" placeholder="请选择业务类型" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'
  import { rules } from '@/utils/rules'


  export default {
    name: 'BuGsfwptJyglForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
       let checkIdentitytionId  = (rule, value, callback) => {
        let errorMsg = this.isIdentityId(value);
        if (errorMsg != "") {
          callback(new Error(errorMsg));
        }
      }
      return {

        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          dzzt: [
            { required: true, message: '请输入代征主体!'},
          ],
          qymc: [
            { required: true, message: '请输入企业名称!'},
          ],
          dlmc: [
            { required: true, message: '请输入代理名称!'},
          ],
          name: [
            { required: true, message: '请输入用户姓名!'},
          ],
          sfzh: [
            { required: true, message: '请输入身份证号!'},
          ],
           jsje: [
              { required: true},
              { pattern: /^(([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!'},
           ],
          ssfwt: [
            { required: true, message: '请输入所属服务厅!'},
          ],
          skssq: [
            { required: true, message: '请输入税款所属期!'},
          ],
          wslx: [
            { required: true, message: '请输入业务类型!'},
          ],
        },
        url: {
          add: "/jygl/buGsfwptJygl/add",
          edit: "/jygl/buGsfwptJygl/edit",
          queryById: "/jygl/buGsfwptJygl/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {

      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }

        })
      },
    }
  }
</script>